<!--已售商品-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="店铺名" prop="shopName">
        <el-input
          v-model="queryParams.shopName"
          placeholder="请输入店铺名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入商品名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="店铺名" align="center" prop="shopName" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="商品" align="left" prop="name" width="700" :show-overflow-tooltip="true"/>
      <!--      1:普通评论2:商家评论-->
      <el-table-column label="已售数量" align="center" prop="totalNum" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="总价" align="center" prop="totalMoney" width="120" :show-overflow-tooltip="true">
        <template slot-scope="scope">{{$yun.priceFormatter(scope.row.totalMoney)}}</template>
      </el-table-column>
      <el-table-column label="最后销售时间" align="center" prop="time" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time, '{m}/{d}/{y}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>
<script>
import {
  list
} from '@/api/store/soldGoods'
import Template from '@/views/setting/template/index.vue'
import { dataList } from '@/api/store/anchorProduct'

export default {
  components: { Template },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      queryParams: {
        'size': 10,
        'current': 1,
        shopName:null,
      },
    }
  },
  created() {
    if(this.$yun.v(this.$route.query, 'shopName')){
      this.queryParams.shopName = this.$yun.v(this.$route.query, 'shopName');
    }
    this.getList()
  },
  methods: {
    /** 查询商品评论列表 */
    getList() {
      this.loading = true
      console.log('this.queryParams',this.queryParams)
      list(this.queryParams).then(response => {
        this.list = response.data.records
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryParams.shopName = null;
      this.handleQuery()
    },
  }
}
</script>
